package com.feicheng.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Role;
import com.feicheng.persistence.service.impl.RoleServiceImpl;

import jakarta.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin/role")
public class RoleController {

	@Autowired
	RoleServiceImpl roleServiceImpl;
	
	@GetMapping("/all")
	public ResultInfo getAllRoles(boolean status) {
		return roleServiceImpl.allRoles(status);
	}
	
	@GetMapping("/page")
	public ResultInfo selectRolesPage(
			String roleName,
            Boolean statu,
            @RequestParam(defaultValue = "1")Integer currentPage,
            @RequestParam(defaultValue = "10")Integer pageSize) {
		return roleServiceImpl.selectRoles(roleName, statu, currentPage, pageSize);
	}
	
	@GetMapping("/info")
	public ResultInfo selectRolesById(String roleCode) {
		return roleServiceImpl.getRoleById(roleCode);
	}
	
	@PostMapping("/info")
	public ResultInfo addRoles(@RequestBody Role role) {
		return roleServiceImpl.addRole(role);
	}
	
	@DeleteMapping("/info")
	public ResultInfo deleteRoleById(String roleCode) {
		return roleServiceImpl.deleteRole(roleCode);
	}
	
	@PutMapping("/info")
	public ResultInfo updateRole(@RequestBody Role role) {
		return roleServiceImpl.updateRole(role);
	}

}
